package cn.bossx.order.controller;


import cn.bossx.basic.util.AjaxResult;
import cn.bossx.basic.util.LoginContext;
import cn.bossx.basic.util.PageList;
import cn.bossx.order.domain.AdoptOrder;
import cn.bossx.order.query.AdoptOrderQuery;
import cn.bossx.order.service.IAdoptOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/adoptOrder")
public class AdoptOrderController {

    @Autowired
    private IAdoptOrderService adoptOrderService;

    /**
     * 领养订单下单接口
     * @param params
     * @param request
     * @return
     */
    @PostMapping("/submit")
    public AjaxResult submit(@RequestBody Map<String,Object> params, HttpServletRequest request){
        try{
            String payData = adoptOrderService.submit(params, LoginContext.getCurrentLogininfo(request));
            System.out.println(payData);
            return AjaxResult.me().setResultObj(payData);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("下单失败！"+e.getMessage());
        }

    }

    //1.后台查询接口  (平台 或者店铺 )
    @PostMapping("/admin")
    public PageList<AdoptOrder> admin(@RequestBody AdoptOrderQuery query, HttpServletRequest request){
        return adoptOrderService.admin(query, LoginContext.getCurrentLogininfo(request));
    }

    //2.用户个人中心我的订单
    @PostMapping("/user")
    public PageList<AdoptOrder> user(@RequestBody AdoptOrderQuery query, HttpServletRequest request){
        return adoptOrderService.user(query, LoginContext.getCurrentLogininfo(request));
    }

    @GetMapping("/{orderId}")
    public AdoptOrder queryById(@PathVariable("orderId") Long id){
        return adoptOrderService.queryById(id);
    }

}